﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress;
using System.Drawing;
using System.ComponentModel;
namespace TimsBaseComponents
{
    public class TextBox : DevExpress.XtraEditors.TextEdit
    {
        public TextBox()
        {

        }
        
        

        private bool _IsEmpty=true;
        [Category("Tims custom Properties")]
        public bool isEmpty
        {
            get
            {
                return _IsEmpty;
            }
        }

        private bool _NeverEmpty;
        [Category("Tims custom Properties")]
        public bool NeverEmpty
        {
            get
            {                
                return  _NeverEmpty;                
            }
            set
            {
                _NeverEmpty = value;
            }
        }

        protected override void OnLoaded()
        {
            if (NeverEmpty)
            {
                this.ToolTip = "";
                this.BackColor = Color.NavajoWhite;
            }
            base.OnLoaded();
        }
        protected override void OnValidating(System.ComponentModel.CancelEventArgs e)
        {
            if (NeverEmpty && string.IsNullOrEmpty(this.Text))
            {
                this.ToolTip = "This field is required";
                this.BackColor = Color.Red ;
            }
            else if (NeverEmpty)
            {
                this.ToolTip = "";
                this.BackColor = Color.NavajoWhite;
            }
            base.OnValidating(e);
        }

        protected override void OnTextChanged(EventArgs e)
        {
            if(string.IsNullOrEmpty(this.Text))
            {
                _IsEmpty = true;
            }
            else
            {
                _IsEmpty = false;
            }
            base.OnTextChanged(e);
        }
    }
}
